package entities.concept;

//import java.util.HashSet;
//import java.util.Set;

import option.KBVocabulary;
import option.QueryKeywords;
import entities.role.Role;

public final class DomainConceptLT<S, T> extends DomainConcept<S, T> {

	public DomainConceptLT(S f, T k) {
		super(f, k);
	}

	@Override
	public boolean equals(Object obj) {
		return super.equals(obj) && this.getClass().equals(obj.getClass());
	}

	private volatile int hashCode = 0;

	@Override
	public int hashCode() {
		if (hashCode != 0) {
			return hashCode;
		}
		final int prime = 31;
		int result = KBVocabulary.LESSTHAN.hashCode();
		result = prime * result + ((f == null) ? 0 : f.hashCode());
		result = prime * result + ((k == null) ? 0 : k.hashCode());
		hashCode = result;
		return result;
	}

	@Override
	public String toString() {
		return "(" + f.toString() + " < " + k.toString() + ")";
	}

	@Override
	public Concept getPrimeCopy() {
		if (this.f instanceof Role) {
			if (this.k instanceof Role) {
				return new DomainConceptLT<Role, Role>(Role.createRoleAsIs(this.f
						.toString() + Concept.PRIME), Role.createRoleAsIs(this.k
						.toString()));
			}
			return new DomainConceptLT<Role, Object>(Role.createRoleAsIs(this.f
					.toString() + Concept.PRIME), this.k);
		} else {
			if (this.k instanceof Role) {
				return new DomainConceptLT<String, Role>(this.f.toString()
						+ Concept.PRIME, Role.createRoleAsIs(this.k.toString()));
			} else {
				return new DomainConceptLT<String, Object>(this.f.toString()
						+ Concept.PRIME, this.k);
			}
		}
	}

	@Override
	public String toSerializedString() {
		return " (" + KBVocabulary.LESSTHAN + " " + this.getSerializedItem(f)
				+ " " + this.getSerializedItem(k) + ")";
	}

	@Override
	public Concept makeParameterized() {
		if (f instanceof String && k instanceof String) {
			return this;
		} else if (f instanceof String) {
			return new DomainConceptLT<Object, String>(k,
					QueryKeywords.PARAMETER);
		} else if (k instanceof String) {
			return new DomainConceptLT<Object, String>(f,
					QueryKeywords.PARAMETER);
		} else {
			return this;
		}
	}

}
